<template>
	<view class="image">
		<view class="image__one" v-if="covers.length == 1 && type != 'edit'">
			<view class="image__one--box">
				<image class="image__one--box-image image__one--box-image1" :src="covers[0].src" mode="aspectFill" @click.stop="e => preview(e,covers[0].src)"></image>
				<view class="image-num" v-if="images.length > covers.length">
					<view class="image-num__icon">
						<image class="image-num__icon--image" src="@/static/theme/default/community/change.png" mode=""></image>
					</view>
					<view class="image-num__info">
						<text class="image-num__info--text">+</text>
						<text class="image-num__info--value">{{images.length}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="image__multiple" v-if="covers.length >= 2 && type != 'edit'">
			<view class="image__multiple--item" v-for="(item,index) in covers" :key="item.src">
				<image class="image__multiple--item-image" :class="['image__multiple--item-image' + (index + 1), index == covers.length - 1 ? 'image-length-' + covers.length : '']" :src="item.src" mode="aspectFill" @click.stop="e => preview(e,item.src)"></image>
				<view class="image-num" v-if="images.length > covers.length && index == covers.length - 1">
					<view class="image-num__icon">
						<image class="image-num__icon--image" src="@/static/theme/default/community/change.png" mode=""></image>
					</view>
					<view class="image-num__info">
						<text class="image-num__info--text">+</text>
						<text class="image-num__info--value">{{images.length}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="image__multiple" v-if="type == 'edit'">
			<view class="image__multiple--item" v-for="(item,index) in covers" :key="item.src">
				<image class="image__multiple--item-image" :class="['image__multiple--item-image' + (index + 1), index == covers.length - 1 ? 'image-length-' + covers.length : '']" :src="item.src" mode="aspectFill" @click.stop="e => preview(e,item.src)"></image>
				<view class="image-num" v-if="images.length > covers.length && index == covers.length - 1">
					<view class="image-num__icon">
						<image class="image-num__icon--image" src="@/static/theme/default/community/change.png" mode=""></image>
					</view>
					<view class="image-num__info">
						<text class="image-num__info--text">+</text>
						<text class="image-num__info--value">{{images.length}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		props: {
			covers: {
				type: Array,
				default: () => []
			},
			images: {
				type: Array,
				default: () => []
			},
			type: {
				type: String,
				default: ''
			},
		},
		methods: {
			preview(e,v) {
				// #ifdef APP-NVUE
				e.stopPropagation();
				// #endif
				let i = 0;
				let urls = [];
				v = v.replace('_minPic','')
				this.images.forEach((item,index) => {
					urls.push(item.src)
					if(item.src == v) i = index
				})
				uni.previewImage({
					urls,
					current: i
				})
				this.$emit('preview')
			}
		}
	}
</script>

<style scoped lang="scss">
	.image {
		
		&__one {
			
			&--box {
				position: relative;
				width: 400rpx;
				height: 300rpx;
				
				&-image {
					border-radius: 10rpx;
					width: 100%;
					height: 100%;
				}
			}
			
		}
		
		&__multiple {
			height: 150rpx;
			display: flex;
			flex-direction: row;
			
			&--item {
				width: calc((100% - 10rpx) / 3);
				height: 150rpx;
				position: relative;
				
				&-image {
					width: 100%;
					height: 150rpx;
				}
				
				&-image1 {
					border-top-left-radius: 10rpx;
					border-bottom-left-radius: 10rpx;
				}
				
				&-image2 {
					margin: 0 5rpx;
				}
				
				&-image3 {
					border-top-right-radius: 10rpx;
					border-bottom-right-radius: 10rpx;
				}
			}
		}
		
	}
	
	.image-num {
		position: absolute;
		right: 5rpx;
		bottom: 5rpx;
		padding: 2rpx 15rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: rgba(0, 0, 0, .6);
		border-radius: 10rpx;
		
		&__icon {
			
			&--image {
				width: 25rpx;
				height: 25rpx;
			}
		}
		
		&__info {
			flex-direction: row;
			align-items: center;
			
			&--text {
				margin: 0 5rpx;
				font-size: 25rpx;
				color: #fff;
			}
			
			&--value {
				font-size: 25rpx;
				color: #fff;
			}
		}
	}
	
	.image-length-2 {
		border-top-right-radius: 10rpx;
		border-bottom-right-radius: 10rpx;
	}
</style>
